//
//  Chufang_EditViewController.m
//  TY-C
//
//  Created by xyyl on 2024/4/19.
//

#import "Chufang_EditViewController.h"
#import "Chufang_addView.h"

@interface Chufang_EditViewController ()
///
@property (nonatomic,strong) UILabel * titleLab;
///处方名称
@property (nonatomic,strong) UILabel * cfLab;
///
@property (nonatomic,strong) UITextField * cfTxt;
///处方类型
@property (nonatomic,strong) UILabel * topLab;
///处方类型选择框
@property (nonatomic,strong) UIButton * topBtn;

///治疗时间
@property (nonatomic,strong) Chufang_addView * zlsjView;
///持续时间
@property (nonatomic,strong) Chufang_addView * cxsjView;

///间隔时间
@property (nonatomic,strong) Chufang_addView * jgsjView;
///上升时间
@property (nonatomic,strong) Chufang_addView * sssjView;
///下降时间
@property (nonatomic,strong) Chufang_addView * xjsjView;
///频率
@property (nonatomic,strong) Chufang_addView * plView;

///脉宽
@property (nonatomic,strong) Chufang_addView * mkView;
///
@property (nonatomic,strong) UIButton * backBtn;
///
@property (nonatomic,strong) UIButton * saveBtn;

@end

@implementation Chufang_EditViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.userInteractionEnabled = YES;
    [self initTopView];
    [self initBottomViews];
}

- (void)initTopView {
    _titleLab = [UILabel new];
    [self.view addSubview:_titleLab];
    _titleLab.frame = CGRectMake(25 * IPADSCALE, 20 * IPADSCALE, 200, 18 * IPADSCALE);
    _titleLab.text = @"编辑处方";
    _titleLab.font = [UIFont boldSystemFontOfSize:20];
    _titleLab.textColor = [UIColor blackColor];
    
    _cfLab = [UILabel new];
    [self.view addSubview:_cfLab];
    _cfLab.frame = CGRectMake(CGRectGetMinX(_titleLab.frame), CGRectGetMaxY(_titleLab.frame)+16, 45 * IPADSCALE, 27 * IPADSCALE);
    _cfLab.text = @"处方名称";
    _cfLab.font = ZYQFONT(18);
    _cfLab.textColor = RGBColor(102, 102, 102);
    
    _cfTxt = [UITextField new];
    [self.view addSubview:_cfTxt];
    _cfTxt.frame = CGRectMake(CGRectGetMaxX(_cfLab.frame), CGRectGetMaxY(_titleLab.frame)+16, 160 * IPADSCALE, 27 * IPADSCALE);
    _cfTxt.placeholder = @"请输入处方名称";
    _cfTxt.backgroundColor = [UIColor whiteColor];
    _cfTxt.clipsToBounds = YES;
    _cfTxt.layer.borderWidth = 1;
    _cfTxt.layer.borderColor = RGBColor(176, 176, 176).CGColor;
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 10, CGRectGetHeight(_cfTxt.frame))];
    imageView.image = [UIImage imageNamed:@"img_none"];
    UIView * leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, CGRectGetHeight(_cfTxt.frame))];
    [leftView addSubview:imageView];
    _cfTxt.leftView = imageView;
    _cfTxt.leftViewMode = UITextFieldViewModeAlways;
    
    
    _topLab =[UILabel new];
    _topBtn = [UIButton new];
    [self.view addSubview:_topBtn];
    [self.view addSubview:_topLab];
    
    [_topBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.top.equalTo(_cfTxt);
        make.right.equalTo(self.view.mas_right).offset(-40*IPADSCALE-LEFTWWW);
    }];
//    [_topBtn setBackgroundImage:[UIImage imageNamed:@"img_select"] forState:0];
    [_topBtn setTitle:@" 低" forState:0];
    [_topBtn setBackgroundColor:[UIColor whiteColor]];
    _topBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    
    _topBtn.titleLabel.font = ZYQFONT(20);
    [_topBtn setTitleColor:RGBColor(51, 51, 51) forState:0];
    [_topBtn addTarget:self action:@selector(topBtnAction) forControlEvents:UIControlEventTouchUpInside];
    _topBtn.clipsToBounds = YES;
    _topBtn.layer.borderWidth = 1;
    _topBtn.layer.borderColor = RGBColor(176, 176, 176).CGColor;
    
    
    
    [_topLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.width.equalTo(self->_cfLab);
        make.right.equalTo(self->_topBtn.mas_left).offset(-5*IPADSCALE);
    }];
    _topLab.text = @"处方类型";
    _topLab.font = ZYQFONT(20);
    _topLab.textColor = RGBColor(102, 102, 102);
    

    _zlsjView = [[Chufang_addView alloc]initWithFrame:CGRectMake(CGRectGetMinX(_cfLab.frame), CGRectGetMaxY(_cfLab.frame)+10*IPADSCALE, ZYQWIDTH - (37+40)*IPADSCALE - LEFTWWW, 27*IPADSCALE)];
    
    [self.view addSubview:_zlsjView];
    
    _cxsjView = [[Chufang_addView alloc]initWithFrame:CGRectMake(CGRectGetMinX(_cfLab.frame), CGRectGetMaxY(_zlsjView.frame)+10*IPADSCALE, CGRectGetWidth(_zlsjView.frame), CGRectGetHeight(_zlsjView.frame))];
    [self.view addSubview:_cxsjView];
    
    _jgsjView = [[Chufang_addView alloc]initWithFrame:CGRectMake(CGRectGetMinX(_cfLab.frame), CGRectGetMaxY(_cxsjView.frame)+10*IPADSCALE, CGRectGetWidth(_zlsjView.frame), CGRectGetHeight(_zlsjView.frame))];
    [self.view addSubview:_jgsjView];
    
    
    _sssjView = [[Chufang_addView alloc]initWithFrame:CGRectMake(CGRectGetMinX(_cfLab.frame), CGRectGetMaxY(_jgsjView.frame)+10*IPADSCALE, CGRectGetWidth(_zlsjView.frame), CGRectGetHeight(_zlsjView.frame))];
    [self.view addSubview:_sssjView];
    
    _xjsjView = [[Chufang_addView alloc]initWithFrame:CGRectMake(CGRectGetMinX(_cfLab.frame), CGRectGetMaxY(_sssjView.frame)+10*IPADSCALE, CGRectGetWidth(_zlsjView.frame), CGRectGetHeight(_zlsjView.frame))];
    [self.view addSubview:_xjsjView];

    _plView = [[Chufang_addView alloc]initWithFrame:CGRectMake(CGRectGetMinX(_cfLab.frame), CGRectGetMaxY(_xjsjView.frame)+10*IPADSCALE, CGRectGetWidth(_zlsjView.frame), CGRectGetHeight(_zlsjView.frame))];
    [self.view addSubview:_plView];
    
    _mkView = [[Chufang_addView alloc]initWithFrame:CGRectMake(CGRectGetMinX(_cfLab.frame), CGRectGetMaxY(_plView.frame)+10*IPADSCALE, CGRectGetWidth(_zlsjView.frame), CGRectGetHeight(_zlsjView.frame))];
    [self.view addSubview:_mkView];

}

- (void)topBtnAction {
    [YBPopupMenu showRelyOnView:_topBtn titles:@[@" 低",@" 中",@" 高"] icons:nil menuWidth:CGRectGetWidth(_topBtn.frame) otherSettings:^(YBPopupMenu *popupMenu) {
        popupMenu.delegate = self;
        popupMenu.tag = 3002;
        popupMenu.font = ZYQFONT(20);
    }];
    
}

- (void)ybPopupMenu:(YBPopupMenu *)ybPopupMenu didSelectedAtIndex:(NSInteger)index {
    NSArray * array11 = @[@" 低",@" 中",@" 高"];
    [_topBtn setTitle:array11[index] forState:0];
}

- (void)initBottomViews {
    
    _backBtn = [UIButton new];
    [self.view addSubview:_backBtn];
    [_backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(80*IPADSCALE));
        make.height.equalTo(@(30*IPADSCALE));
        make.bottom.equalTo(self.view.mas_bottom).offset(-15*IPADSCALE);
        make.right.equalTo(self.view.mas_centerX).offset(-50*IPADSCALE);
    }];
    [_backBtn setTitle:@"返回" forState:0];
    [_backBtn setTitleColor:RGBColor(13, 157, 219) forState:0];
    _backBtn.titleLabel.font = [UIFont boldSystemFontOfSize:30];
    _backBtn.clipsToBounds = YES;
    _backBtn.layer.borderWidth = 1;
    _backBtn.layer.cornerRadius = 15*IPADSCALE;
    _backBtn.layer.borderColor = RGBColor(13, 157, 219).CGColor;
    
    _saveBtn = [UIButton new];
    [self.view addSubview:_saveBtn];
    [_saveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.height.width.equalTo(_backBtn);
        make.left.equalTo(_backBtn.mas_right).offset(30*IPADSCALE);
    }];
    [_saveBtn setTitle:@"保存" forState:0];
    [_saveBtn setTitleColor:[UIColor whiteColor] forState:0];
    _saveBtn.titleLabel.font = [UIFont boldSystemFontOfSize:30];
    _saveBtn.clipsToBounds = YES;
    _saveBtn.layer.borderWidth = 1;
    _saveBtn.layer.cornerRadius = 15*IPADSCALE;
    _saveBtn.layer.borderColor = RGBColor(13, 157, 219).CGColor;
    [_saveBtn setBackgroundColor:RGBColor(13, 157, 219)];
    
    
    _saveBtn.tag = 1;
    _backBtn.tag = 0;
    
    [_saveBtn addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [_backBtn addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];

}

- (void)backBtnAction:(UIButton *)btn {
    if(btn.tag == 1){
        ///保存操作
    }
    [self.view removeFromSuperview];///移除view
    [self removeFromParentViewController];///移除父控制器
}

- (void)dealloc {
    NSLog(@"222222222");
}

@end
